package com.taobao.txc.parser.struct;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.taobao.txc.common.LoggerInit;
import com.taobao.txc.common.LoggerWrap;
import com.taobao.txc.common.a.a;
import com.taobao.txc.parser.b.a.g;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang.StringUtils;

public class TxcRuntimeContext
{
  private static final LoggerWrap a = LoggerInit.logger;
  public long id = 0L;
  public String xid;
  public String writeKeys;
  public long branchId = 0L;
  @JSONField(serialize=false)
  private List<c> b = new ArrayList();
  @JSONField(serialize=false)
  private List<i> c = new ArrayList();
  public c[] info;
  public int status;
  public String server;
  @JSONField(serialize=false)
  private final long start = System.currentTimeMillis();
  @JSONField(serialize=false)
  private long start0 = System.currentTimeMillis();
  @JSONField(serialize=false)
  private i d = new i(this, null);
  
  public TxcRuntimeContext a(long paramLong)
  {
    this.d.b = paramLong;
    return this;
  }
  
  public TxcRuntimeContext b(long paramLong)
  {
    this.d.d = paramLong;
    return this;
  }
  
  public TxcRuntimeContext c(long paramLong)
  {
    this.d.c = paramLong;
    return this;
  }
  
  public String encode()
  {
    this.info = new c[this.b.size()];
    this.b.toArray(this.info);
    for (c localc : this.info)
    {
      TxcTable localTxcTable = localc.a;
      localTxcTable.line = new TxcLine[localTxcTable.c().size()];
      localTxcTable.c().toArray(localTxcTable.line);
      TxcLine localTxcLine;
      for (localTxcLine : localTxcTable.line)
      {
        localTxcLine.fields = new TxcField[localTxcLine.a().size()];
        localTxcLine.a().toArray(localTxcLine.fields);
      }
      localTxcTable = localc.b;
      localTxcTable.line = new TxcLine[localTxcTable.c().size()];
      localTxcTable.c().toArray(localTxcTable.line);
      for (localTxcLine : localTxcTable.line)
      {
        localTxcLine.fields = new TxcField[localTxcLine.a().size()];
        localTxcLine.a().toArray(localTxcLine.fields);
      }
      if (a.c()) {
        a.debug(localc.a());
      }
    }
    return JSON.toJSONString(this, new SerializerFeature[] { SerializerFeature.WriteDateUseDateFormat });
  }
  
  public static TxcRuntimeContext decode(String paramString)
  {
    TxcRuntimeContext localTxcRuntimeContext = (TxcRuntimeContext)JSON.parseObject(paramString, TxcRuntimeContext.class);
    if ((localTxcRuntimeContext.info != null) && (localTxcRuntimeContext.info.length > 0))
    {
      localTxcRuntimeContext.b.clear();
      for (c localc : localTxcRuntimeContext.info)
      {
        TxcTable localTxcTable = localc.c();
        TxcLine localTxcLine;
        TxcField localTxcField;
        if ((localTxcTable.line != null) && (localTxcTable.line.length > 0))
        {
          localTxcTable.c().clear();
          for (localTxcLine : localTxcTable.line)
          {
            if ((localTxcLine.fields != null) && (localTxcLine.fields.length > 0))
            {
              localTxcLine.a().clear();
              for (localTxcField : localTxcLine.fields) {
                localTxcLine.a().add(localTxcField);
              }
            }
            localTxcTable.c().add(localTxcLine);
          }
        }
        localTxcTable = localc.e();
        if ((localTxcTable.line != null) && (localTxcTable.line.length > 0))
        {
          localTxcTable.c().clear();
          for (localTxcLine : localTxcTable.line)
          {
            if ((localTxcLine.fields != null) && (localTxcLine.fields.length > 0))
            {
              localTxcLine.a().clear();
              for (localTxcField : localTxcLine.fields) {
                localTxcLine.a().add(localTxcField);
              }
            }
            localTxcTable.c().add(localTxcLine);
          }
        }
        localTxcRuntimeContext.b.add(localc);
      }
    }
    return localTxcRuntimeContext;
  }
  
  public String a()
  {
    return this.xid;
  }
  
  public void a(String paramString)
  {
    this.xid = paramString;
  }
  
  public long b()
  {
    return this.branchId;
  }
  
  public void d(long paramLong)
  {
    this.branchId = paramLong;
  }
  
  public List<c> c()
  {
    return this.b;
  }
  
  public void a(c paramc)
  {
    this.b.add(paramc);
  }
  
  public int d()
  {
    return this.status;
  }
  
  public void a(int paramInt)
  {
    this.status = paramInt;
  }
  
  public String e()
  {
    return this.server;
  }
  
  public void b(String paramString)
  {
    this.server = paramString;
  }
  
  public String f()
  {
    return this.writeKeys;
  }
  
  public void c(String paramString)
  {
    if (StringUtils.isEmpty(paramString)) {
      return;
    }
    if (StringUtils.isEmpty(this.writeKeys)) {
      this.writeKeys = paramString;
    } else {
      this.writeKeys = String.format("%s;%s", new Object[] { this.writeKeys, paramString });
    }
  }
  
  public long g()
  {
    return System.currentTimeMillis() - this.start;
  }
  
  public boolean h()
  {
    return this.branchId > 0L;
  }
  
  public long i()
  {
    long l = System.currentTimeMillis() - this.start0;
    this.start0 = System.currentTimeMillis();
    return l;
  }
  
  public void a(g paramg)
  {
    TxcTable localTxcTable1 = paramg.c();
    TxcTable localTxcTable2 = paramg.d();
    if ((localTxcTable1.b() == 0) && (localTxcTable2.b() == 0)) {
      return;
    }
    c localc = new c();
    localc.d(paramg.j().a());
    localc.a(paramg.j().d());
    localc.b(paramg.g());
    localc.a(localTxcTable1);
    localc.b(localTxcTable2);
    localc.a(paramg.e());
    switch (h.a[paramg.j().d().ordinal()])
    {
    case 1: 
      localc.c(paramg.c(localTxcTable1));
      break;
    case 2: 
      localc.c(paramg.c(localTxcTable1));
      break;
    case 3: 
      localc.c(paramg.c(localTxcTable2));
      break;
    case 4: 
      localc.c(paramg.c(localTxcTable2));
      break;
    default: 
      throw new SQLException("unsupported sqltype:" + paramg.j().d().a());
    }
    localc.b();
    a(localc);
    k();
  }
  
  private void k()
  {
    if (a.b())
    {
      this.d.a = a.a().d();
      this.c.add(this.d);
      this.d = new i(this, null);
    }
  }
  
  @JSONField(serialize=false)
  public String j()
  {
    StringBuilder localStringBuilder = new StringBuilder();
    int i = 1;
    Iterator localIterator = this.c.iterator();
    while (localIterator.hasNext())
    {
      i locali = (i)localIterator.next();
      if (i != 0) {
        i = 0;
      } else {
        localStringBuilder.append(",");
      }
      localStringBuilder.append(locali.a).append('/').append(locali.b).append('/').append(locali.c).append('/').append(locali.d);
    }
    return localStringBuilder.toString();
  }
}


/* Location:           C:\Users\ibm\Downloads\txc-yun-sample (1)\txc-yun-sample\lib\txc-client-2.0.72.jar
 * Qualified Name:     com.taobao.txc.parser.struct.TxcRuntimeContext
 * JD-Core Version:    0.7.0.1
 */